package br.eng.eliseu.gwt.gestaoWeb.model.endereco;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;

import br.eng.eliseu.gwt.gestaoWeb.model.BaseEntity;

@Entity
@SequenceGenerator(name="SQ_PAIS", sequenceName="SQ_PAIS")
@NamedQueries({
	@NamedQuery(name="pais.todos", query="select b from Pais b order by b.nome"),
	@NamedQuery(name="pais.porNome", query="select b from Pais b where b.nome = :nome order by b.nome")
})

public class Pais extends BaseEntity {


	public Pais() {}
	
	@Id
	@GeneratedValue(generator="SQ_PAIS", strategy=GenerationType.AUTO)
	private Integer id;
	
	@Column(length=254)
	private String nome;

	@Column(length=254)
	private String nomeCompleto;
	
	private Integer ddi;
	
	@Column(length=2)
	private String siglaISO2;
	
	@Column(length=3)
	private String siglaISO3;
	
	@Override
	public String toString() {
		if (getNome()!=null){
			return getNome();
		}
		return super.toString();
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getNomeCompleto() {
		return nomeCompleto;
	}
	public void setNomeCompleto(String nomeCompleto) {
		this.nomeCompleto = nomeCompleto;
	}
	public Integer getDdi() {
		return ddi;
	}
	public void setDdi(Integer ddi) {
		this.ddi = ddi;
	}
	public String getSiglaISO2() {
		return siglaISO2;
	}
	public void setSiglaISO2(String siglaISO2) {
		this.siglaISO2 = siglaISO2;
	}
	public String getSiglaISO3() {
		return siglaISO3;
	}
	public void setSiglaISO3(String siglaISO3) {
		this.siglaISO3 = siglaISO3;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ddi == null) ? 0 : ddi.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		result = prime * result
				+ ((nomeCompleto == null) ? 0 : nomeCompleto.hashCode());
		result = prime * result
				+ ((siglaISO2 == null) ? 0 : siglaISO2.hashCode());
		result = prime * result
				+ ((siglaISO3 == null) ? 0 : siglaISO3.hashCode());
		return result;
	}

	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pais other = (Pais) obj;
		if (ddi == null) {
			if (other.ddi != null)
				return false;
		} else if (!ddi.equals(other.ddi))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		if (nomeCompleto == null) {
			if (other.nomeCompleto != null)
				return false;
		} else if (!nomeCompleto.equals(other.nomeCompleto))
			return false;
		if (siglaISO2 == null) {
			if (other.siglaISO2 != null)
				return false;
		} else if (!siglaISO2.equals(other.siglaISO2))
			return false;
		if (siglaISO3 == null) {
			if (other.siglaISO3 != null)
				return false;
		} else if (!siglaISO3.equals(other.siglaISO3))
			return false;
		return true;
	}
	public int compareTo(Pais obj) {
		return getNome().compareTo(obj.getNome());
	}
}